<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>石材排名设置</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" href="admin/css/common.css" type="text/css" />
<link rel="stylesheet" href="admin/css/provider.css" type="text/css" />
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="admin/js/mulselect.js"></script>
<script type="text/javascript">
	function check(){
		$('#selectedProviders').val("0");
		var sel = document.getElementById('selProviders');
		var s = ""
		for(var i=0; i < sel.options.length; i++){
			if(sel.options[i]) s += sel.options[i].value + ";";
			}
		s = s.substr(0,s.length-1);
		$('#selectedProviders').val(s);
		alert('保存成功!');
	}
	

	function loadProvider(obj){
		var pageno = parseInt($('#pageNo').val());
		if( obj == 'left'){
			if(pageno == 1){
			}else{
				$('#pageNo').val(pageno -1);
			}
		}else if(obj == 'right'){
			$('#pageNo').val(pageno +1);
		}else{
			$('#pageNo').val(1);
		}
		var param ={ pageno: parseInt($('#pageNo').val()) ,
				 pageSize:50,
				 providerName: $('#providerName').val()	};
		jQuery.post("findProviderListAjax.action",param,callbackFunc,"json");
	}

	function callbackFunc(data){
		var temp = "";
		temp += '<select  class="sel" multiple="multiple" size="20" name="allProviders" id="allProviders" ondblclick="move(this.form.allProviders,this.form.selProviders)">';
		for(i=0 ; i < data.listSize;i++ ){
			temp += '<option value="'+data.providerList[i].id+'">';
			temp += data.providerList[i].name;
			temp += '</option>';
		}
		temp += '</select>';
		$('#allProvidersDiv').html(temp);
		if(data.page.currentPage == 1 || data.page.totalPages == 1){
			$('#leftBtn').hide();
		}else{
			$('#leftBtn').show();
		}
		if(data.page.totalPages == 1 || data.page.currentPage == data.page.totalPages ){
			$('#rightBtn').hide();
		}else{
			$('#rightBtn').show();
		}
	}
</script>
</head>
<body>
	<div id="provider_zone">
		<form action="rank/saveProviderRank.action" name="providerForm"
			method="post" onsubmit="return check();">
			<input type="hidden" value="供应商" name="category"/>
			<table width="80%" border="0" align="center" cellpadding="3"
				cellspacing="1" class="table_style">
				<tr class="head">
					<th width="260px">可供选择的公司</th>
					<th width="100px">操作</th>
					<th width="260px">公司排名</th>
				</tr>
				<tr>
					<td style="text-align: center;">
					 	<input type="text" class="search-input" value="${providerName }" name="providerName" id="providerName" onkeyup="loadProvider()" title="输入公司名字搜索关键字" />
			      	 	<br/>
			      	 	第<input type="text" value="1" name="pageNo" id="pageNo" size="1"  style="text-align: center;"/>页
			      		<input type="button" value="上一页" onclick="loadProvider('left');" id="leftBtn"/> 
			      		<input type="button" value="下一页" onclick="loadProvider('right');"  id="rightBtn"/>
						<div id="allProvidersDiv">
							<select class="sel" multiple="multiple" size="20"
								name="allProviders" id="allProviders"
								ondblclick="move(this.form.allProviders,this.form.selProviders)"> 
								<c:forEach items="${providersList }" var="providerItem">
									<option value="${providerItem.id }">
										${providerItem.name }</option>
								</c:forEach>
							</select>
						</div></td>
					<td style="text-align: center; background-color: #ffffff;"><input
						type="button" class="btn" value="全部右移"
						onclick="moveall(this.form.allProviders,this.form.selProviders)"
						name="B1">
						<p></p> <input type="button" class="btn" value="选中右移"
						onclick="move(this.form.allProviders,this.form.selProviders)" name="B2">
						<p></p> <input type="button" class="btn" value="选中左移"
						onclick="move(this.form.selProviders,this.form.allProviders)" name="B3">
						<p></p> <input type="button" class="btn" value="全部左移"
						onclick="moveall(this.form.selProviders,this.form.allProviders)"
						name="B4"></td>
					<td style="text-align: center;" id="selProvidersDiv"><select class="sel"
						multiple="multiple" size="20" name="selProviders" id="selProviders"
						ondblclick="move(this.form.selProviders,this.form.allProviders)"> 
		      		 <c:forEach items="${alreadyRankedProvidersList }" var="item">
						<option value="${item.id }">
							${item.name }
						</option>
					</c:forEach>
					</select> 
					</td>
					<input type="hidden" id="selectedProviders" name="selectedProviders" />
				</tr>
				<tr>
					<td colspan="3" class="left_title_2"><input type="submit"
						class="input-submit" value="保存"></td>
				</tr>
			</table>
		</form>
	</div>
</body>
<script type="text/javascript">
	SortD(document.getElementById('allProviders'));
	SortD(document.getElementById('selProviders'));
</script>
</html>
